//
//  TableViewModel+ButtonRows.swift
//  CooperSwift
//
//  Created by 计海峰 on 2022/1/17.
//

import Foundation

public extension TableViewModelProtocol {
    //MARK: - btn cell
    /// btn config   vm 需要 BindKeyProtocol 
    func btnConfig(_ text: String = "", method: String = "btnTap", color: UIColor = .white, bgColor: UIColor = .blue, frame: CGRect? = nil) -> TableShowBtnConfig {
        let btnConfig = TableShowBtnConfig(text).then {
            $0.method = method
            $0.text = text
            $0.bgColor = bgColor
            $0.textColor = color
            if let btnFrame = frame {
                $0.frame = btnFrame
            }
        }
        return btnConfig
    }
    
    /// btn cell
    func btnRow(_ text: String = "", method: String = "btnTap", color: UIColor = .white, bgColor: UIColor = .blue, frame: CGRect? = nil, cellHeight: CGFloat? = nil, key: String? = nil, isTarget: Bool = true) -> TableShowBtnCellModel {
        let btnCellModel = TableShowBtnCellModel(btnConfig(text, method: method, color: color, bgColor: bgColor, frame: frame)).then {
            if let bindKey = key {
                $0.addTargetKey(bindKey, isTarget: isTarget)
            }
            if let height = cellHeight {
                $0.cellHeight = height
            }
        }
        return btnCellModel
    }
    
    /// btns cell
    func btnsRow(_ configs: [TableShowBtnConfig], cellHeight: CGFloat? = nil, key: String? = nil, isTarget: Bool = true) -> TableShowBtnCellModel {
        let btnCellModel = TableShowBtnCellModel(configs).then {
            if let bindKey = key {
                $0.addTargetKey(bindKey, isTarget: isTarget)
            }
            if let height = cellHeight {
                $0.cellHeight = height
            }
        }
        return btnCellModel
    }
    
}
